package encheres.presentation.ui;

import javax.swing.JTextField;
import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class JTextLimitedFloat extends PlainDocument {

	private JTextField chaine;
	
	public JTextLimitedFloat(JTextField chaine) {
		super();
		this.chaine = chaine;
	}

	public void insertString(int offset, String str, AttributeSet attr)
			throws BadLocationException {
		try {
			if(!(str.equals(".") && this.chaine.getText().indexOf('.') == -1)) {
				Float.parseFloat(str);
			}
			super.insertString(offset, str, attr);
			
		} catch (Exception e) {
			// ..On ne fait rien
		}
	}
}